//
//  TaskBean.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/3/14.
//

import Foundation
import GRDB

class TaskBean : ICloudTable,IDbTable, Identifiable {
    
    static let databaseTableName = "task"

    
    func getCloudTable() -> String {
        "task"
    }
    
    //leanCloud 排除字段
    func doCustomExcluded() -> [String? : Any?] {
        return doExcluded(subject: self, excluded: ["modifySign","status"])
    }
    
    
    //db排除字段
    func doCustomDBExcluded()  -> [String? : Any?] {
        return doExcluded(subject: self, excluded: [""])
    }
    
    
    var objectId: String?
    var time: Int64 = 0//执行任务时间,单位毫秒
    var name: String? = nil//任务名称
    var timeKey: String? = nil //2024-10-30  日期为key，唯一性， 用于今天已经创建过任务了
    var roleId: String? = nil//角色id
    var userId: String? = nil
    var type: Int = ITaskType.CALL.rawValue//任务类型，
    var execute: Bool = false//是否已执行
    var extra: String? = nil//额外数据

    var modifySign: Bool = false//修改标识
    var status : Int = IStatusType.NORMAL.rawValue
    
    //json解析白名单
    private enum CodingKeys: String, CodingKey {
        case objectId
        case time
        case name
        case timeKey
        case roleId
        case userId
        case type
        case execute
        case extra

        //case modifySign
        //case status
    }
}


extension TaskBean {
    // db数据库指定字段
    public func encode(to container: inout PersistenceContainer) {
        doDBExcluded(to: &container)
    }
}
